package logic

import (
	"context"

	"godco/internal/svc"
	"godco/internal/types"
	u "godco/internal/model/users"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserSignLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserSignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserSignLogic {
	return &UserSignLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserSignLogic) UserSign(req *types.SignRequest) (resp *types.SignResp, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, req.Email)
	if err == u.ErrNotFound {
		data := u.User{Name:req.Name,Email:req.Email,State:"yes"}
		err = l.svcCtx.UserModel.Insert(l.ctx,&data)
		if err != nil{
			resp = &types.SignResp{
				Code:       403,
				Message:    err.Error(),
			}
			return resp, nil
		}
	}
	resp = &types.SignResp{
		Code:       0,
		Message:    "success",
	}
	return resp, nil
}
